package controller;

import bean.Emp;
import bean.ResultCode;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import service.EmpService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpController {
    @Resource
    private EmpService empService;

    @GetMapping(value = "/find",produces = {"application/json;charset=utf-8"})
    public String find(@RequestParam(name="page",defaultValue =" 1") int page){
        PageInfo<Emp> list = empService.findAllEmp(page);
        ResultCode<PageInfo<Emp>> result=new ResultCode<>(200,null,list);
        return JSONArray.toJSONString(result);
    }

    //删除一般使用的是delete请求
    @DeleteMapping(value = "/delete",produces = {"applicaiton/json;charset=utf-8"})
    public String delete(int id){
        PageInfo<Emp> list = empService.deleteEmp(id);
        ResultCode<PageInfo<Emp>> result=new ResultCode<>(200,null,list);
        return JSONArray.toJSONString(result);
    }

}
